package com.yww.leetcode2.stack_queue;

import java.util.Stack;

/**
 * @author yww
 * @description 232. 用栈实现队列
 * @since 2024/11/20
 */
public class MyQueue232_01 {
    // 入栈
    private final Stack<Integer> stackIn = new Stack<>();
    // 出栈
    private final Stack<Integer> stackOut = new Stack<>();

    public MyQueue232_01() {
    }

    public void push(int x) {
        // 入栈
        stackIn.push(x);
    }

    public int pop() {
        // 如果出栈空，将入栈的数据反转到出栈
        if (stackOut.isEmpty()) {
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
        // 出栈弹出元素
        return stackOut.pop();
    }

    public int peek() {
        int pop = this.pop();
        stackOut.push(pop);
        return pop;
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }
}
